// pages/doc/index.js
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      type:5,
      content:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      let type = options.type;
      let title;
      if(type == 1) title="产品介绍";
      if(type == 2) title="适用人群";
      if(type == 3) title="研发背景";
      if(type == 4) title="关于我们";
      if(type == 5) title="使用教程";
      wx.setNavigationBarTitle({
        title: title,
      })
      this.getData(type)
  },
  getData(type){
    app.post('index/article',{
      type:type
    }).then(res=>{
        var content = res.data.content.replace(/<\/?(img)[^>]*>/gi, function(text){
          let src = text.match(/src=[\'\"]?([^\'\"]*)[\'\"]?/i)[1]
          let img = `<img src="${src}"  style="max-width:100%;height:auto;margin:5px auto;"/>`
          return img
        })
        console.log(content)
        this.setData({
          content:content
        })
    })
  }
})